package com.atxwq.shop.manager.controller;

import com.atxwq.shop.manager.serivce.CategoryService;
import com.atxwq.shop.model.entity.product.Category;
import com.atxwq.shop.model.vo.common.Result;
import com.atxwq.shop.model.vo.common.ResultCodeEnum;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Description 分类相关接口
 * @Date 2025/5/13 09:57
 * @Created by 12336
 */

@RestController
@RequestMapping("admin/product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 分类列表，每次只查一层数据，提高效率
     * @param id
     * @return
     */
    @GetMapping("/findCategoryList/{id}")
    public Result findCategoryList(@PathVariable("id") Long id){
        List<Category> list = categoryService.findCategoryList(id);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    /**
     * 导出数据
     * 不需要返回json数据
     * @param response
     */
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }

    /**
     * 导入数据
     * @param
     * @return
     */
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
